/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.statemachine.figure;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Shape;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.RGB;

import com.cea.papyrus.core.PapyrusPlugin;

/**
 * PseudostateExitPointFigure.
 * 
 * @author David Servat
 * @since 10 apr. 07
 */
public class ConnectionPointReferenceFigure extends Shape{

	/**
	 * kind
	 */
	protected int kind = 0;

	public void setKind(int kind){
		this.kind = kind;
	}

	/**
	 * Default Constructor.
	 */
	public ConnectionPointReferenceFigure(){
		super();
	}

	/**
	 * Does nothing.
	 * @see org.eclipse.draw2d.Shape#fillShape(org.eclipse.draw2d.Graphics)
	 */
	@Override
	protected void fillShape(Graphics graphics){
	}

	/**
	 * @see org.eclipse.draw2d.Shape#outlineShape(org.eclipse.draw2d.Graphics)
	 */
	@Override
	protected void outlineShape(Graphics graphics){
		graphics.pushState();
		if(((RegionFigure)getParent().getParent().getParent()).getBorderColor() != null){
			graphics.setForegroundColor(((RegionFigure)getParent().getParent().getParent()).getBorderColor());
		}
		if(((RegionFigure)getParent().getParent().getParent()).getBackgroundColor() != null){
			graphics.setBackgroundColor(((RegionFigure)getParent().getParent().getParent()).getBackgroundColor());
		}
		Rectangle r = Rectangle.SINGLETON;
		r.setBounds(getBounds());
		r.shrink(1,1);
		graphics.drawOval(r);
		r.shrink(1,1);
		graphics.fillOval(r);

		if(kind == 0){
			r.x += r.width/4;
			r.y += r.height/7;
			r.width = r.width/2;
			r.height = r.height/2;
			graphics.setForegroundColor(PapyrusPlugin.colorManager.get(new RGB(255, 0, 0)));
			graphics.setBackgroundColor(PapyrusPlugin.colorManager.get(new RGB(255, 0, 0)));
			graphics.setLineWidth(2);
			graphics.drawArc(r, 0, 180);
			r.x += r.width/2;
			r.y += r.height/2;
			graphics.drawArc(r, 90, 90);
			r.x -= r.width/4;
			r.y += 0.75*r.height;
			r.width =  Math.max((int)r.width/2, 2); 
			r.height = Math.max((int)r.height/2, 2);
			graphics.fillOval(r);
		}
		else if(kind == 2){
		      //intersection coordinates.
	        int x = (int) ((bounds.width-1) / (2 * Math.sqrt(2)));
	        int y = (int) ((bounds.height-1) / (2 * Math.sqrt(2)));

	        //cross.
	        graphics.drawLine(bounds.getCenter().translate(x, -y), bounds.getCenter().translate(-x, y));
	        graphics.drawLine(bounds.getCenter().translate(-x, -y), bounds.getCenter().translate(x, y));
		}
		graphics.popState();
	}
}